package com.ruoyi.generator.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.generator.domain.ColumnInfo;
import com.ruoyi.generator.domain.TableInfo;
import com.ruoyi.generator.service.IGenService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@Controller
@RequestMapping("/columnInfoController")
public class ColumnInfoController  extends BaseController {
    private String prefix = "tool/gen";
    @Autowired
    private IGenService genService;
    /**
     * 生成代码
     */
    @Log(title = "代码生成", businessType = BusinessType.GENCODE)
    @GetMapping("/tableInfo/{tableName}")
    public String tableInfo(HttpServletResponse response, @PathVariable("tableName") String tableName, Model model) throws IOException
    {
        model.addAttribute("tableName",tableName);
        return prefix+"/columnInfo";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ColumnInfo columnInfo, String tableName)
    {
//        startPage();
        List<ColumnInfo> list = genService.selectTableColumnsByName(tableName);
        return getDataTable(list);
    }
}
